package com.zjsru.oneDay202205;

/**
 * @Author: likew
 * @Date: 2022/5/12
 *
 * 删列造序,返回你需要删除的列数。
 *
 * 输入：strs = ["cba","daf","ghi"]
 * 输出：1
 * 解释：网格示意如下：
 *   cba
 *   daf
 *   ghi
 * 列 0 和列 2 按升序排列，但列 1 不是，所以只需要删除列 1 。
 *
 */
public class minDeletionSize {
    public int minDeletionSize(String[] strs) {
        int n = strs.length, m = strs[0].length(), ans = 0;
        out:for (int i = 0; i < m; i++) {
            for (int j = 0, cur = -1; j < n; j++) {
                int t = strs[j].charAt(i);
                if(t < cur && ++ans > 0) continue out;
                cur = t;
            }
        }
        return ans;
    }
    
    public static void main(String[] args) {
        minDeletionSize minDeletionSize = new minDeletionSize();
        String[] strs = new String[]{"cba","daf","ghi"};
        System.out.println(minDeletionSize.minDeletionSize(strs));
    }
}
